package com.firebird.app.kotlin.stock.base

import android.os.Bundle
import android.os.PersistableBundle
import androidx.annotation.Nullable
import androidx.lifecycle.Lifecycle
import com.uber.autodispose.AutoDispose
import com.uber.autodispose.AutoDisposeConverter
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider


/**
 * @author ljk
 * @date 2020/1/1.
 * Description：
 */
abstract class BaseMvpActivity<T : BasePresenter<BaseView>> : BaseActivity(), BaseView {
//abstract class BaseMvpActivity<T : BasePresenter<BaseView>?> : BaseActivity(), BaseView {
     var mPresenter: T? = null

    override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
        super.onCreate(savedInstanceState, persistentState)
    }

   // override fun onCreate(@Nullable savedInstanceState: Bundle?) {
   //     super.onCreate(savedInstanceState)
   // }

    override fun onDestroy() {
        if (mPresenter != null) {
            mPresenter?.detachView()
        }
        super.onDestroy()
    }

    /**
     * 绑定生命周期 防止MVP内存泄漏
     *
     * @param <T>
     * @return
    </T> */
    override fun <T> bindAutoDispose(): AutoDisposeConverter<T> {
        return AutoDispose.autoDisposable(AndroidLifecycleScopeProvider
                .from(this, Lifecycle.Event.ON_DESTROY))
    }
}